/*
 * MessageBodyWriterJSON.java
 *
 * Copyright©2012 JMAS corporation. All rights reserved.
 */
package jp.co.jmas.jmasvideo.service;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

/**
 * @author toshio
 * @see http://stackoverflow.com/questions/4428109/jersey-jackson-json-date-serialization-format-problem-how-to-change-the-form
 */
@Provider
public class MessageBodyWriterJSON extends JacksonJsonProvider {
	public MessageBodyWriterJSON() {
		// do nothing
	}

	@Override
	public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) {
		ObjectMapper mapper = super.locateMapper(type, mediaType);

		// Enabled pretty print formatting
		mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);

		// DateTime in ISO format "2012-04-07T17:00:00.000+0000" instead of 'long' format
		mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
		return mapper;
	}
}